#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const int N = 15;

int n;
bool st[N];
vector<int> path;

void dfs()
{
	if(path.size() == n)
	{
		for(auto e : path) printf("%5d", e);
		cout << endl;

		return;
	}

	for(int i = 1; i <= n; i++)
	{
		if(st[i]) continue;

		path.push_back(i);
		st[i] = true;
		dfs();
		//恢复现场
		path.pop_back();
		st[i] = false;
	}
}

int main()
{
	cin >> n;

	dfs();

	return 0;
}

